package bma.common.netty.webserver.common;

import java.util.ArrayList;
import java.util.List;

import bma.common.langutil.ai.stack.AIStack;
import bma.common.netty.webserver.RequestContext;
import bma.common.netty.webserver.RequestDispatcher;
import bma.common.netty.webserver.RequestProcessor;

public class RequestDispatcherChain extends RequestDispatcher {

	protected List<RequestProcessor> chain = new ArrayList<RequestProcessor>();

	@Override
	public boolean dispatch(AIStack<Boolean> stack, RequestContext ctx)
			throws Exception {
		for (RequestProcessor p : chain) {
			if (dispatchOrProcess(stack, p, ctx)) {
				return true;
			}
		}
		return false;
	}

	public List<RequestProcessor> getChain() {
		return chain;
	}

	public void addDispatcherList(List<RequestDispatcher> list) {
		this.chain.addAll(list);
	}

	public void addProcessorList(List<RequestProcessor> list) {
		this.chain.addAll(list);
	}

	public void setDispatcher(RequestDispatcher dis) {
		this.chain.add(dis);
	}

	public void setProcessor(RequestProcessor p) {
		this.chain.add(p);
	}

	public void addDispatcher(RequestDispatcher dis) {
		this.chain.add(dis);
	}

	public void addProcessor(RequestProcessor p) {
		this.chain.add(p);
	}

}
